package com.xie.smfs.effect;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.entity.player.PlayerEntity;

public class FatalPoisonEffect extends StatusEffect {
    public FatalPoisonEffect() {
        super(StatusEffectCategory.HARMFUL, 0x44FF44);
    }

    @Override
    public boolean canApplyUpdateEffect(int duration, int amplifier) {
        // 降低伤害频率：每60tick（2秒）造成一次伤害，原版为20tick（1秒）
        return duration % 60 == 0;
    }

    @Override
    public void applyUpdateEffect(LivingEntity entity, int amplifier) {
        if (entity instanceof PlayerEntity player) {
            // 移除半颗心限制，直接造成伤害
            if (player.getHealth() > 0) {
                player.damage(player.getDamageSources().magic(), 1.0F * (amplifier + 1));
            }
        } else {
            entity.damage(entity.getDamageSources().magic(), 1.0F * (amplifier + 1));
        }
    }
}